<html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <?php $this->load->view('title'); ?>
        <link rel="shortcut icon" href="<?php echo base_url() ?>front-end/images/ac_logo.ico">
        <link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>front-end/css/common.css">
        <link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>front-end/css/building.css">
        <script type="text/javascript" src="<?php echo base_url() ?>front-end/js/jquery.min.js"></script>        
        <link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>front-end/css/jquery.mCustomScrollbar.css">
        <script type="text/javascript" src="<?php echo base_url() ?>front-end/js/jquery.mCustomScrollbar.concat.min.js"></script>
        <script>
            $(document).ready(function(){
                var isGetMore = false;
                var offset = 10;
                var NoData = false;
                $("#VanChuongContent").mCustomScrollbar({
                    autoDraggerLength: false,
                    scrollButtons:{
                        enable: true
                    },
                    advanced:{
                        updateOnContentResize: true
                    },
                    callbacks:{
                        whileScrolling: function(){
                            if ((mcs.draggerTop/$(this).height() >= 0.7) && (!isGetMore)){
                                var container = $(this).children().children().first();
                                if (NoData){
                                    
                                }else{
                                    $.ajax({
                                        type: 'get',
                                        url: '/news/loadmore/'+offset,
                                        dataType: 'json',
                                        data:null,
                                        beforeSend: function(){
                                            isGetMore = true;
                                            var html = '<div id="loading"><a title="" class="Thumnail"><img style="width: 10%; border: none;" src="<?php echo base_url() ?>front-end/images/loading.gif" alt="loading"></a></div>';
                                            container.append(html); 
                                        },
                                        success: function(data){
                                            $("#loading").remove();
                                            isGetMore = false;
                                            if (data.length == 0){
                                                NoData = true;
                                            }else{
                                                offset +=10;
                                                var html;
                                                for (i = 0; i < data.length; i++){
                                                    var desc='';
                                                    if(data[i].description.length<200)
                                                    {
                                                        desc = data[i].description;
                                                    }
                                                    else
                                                    {
                                                        desc = data[i].description.substr(0, 200)+'...';
                                                    }
                                            
                                                    html = '';    
                                                    html+='<div class="news-item">';
                                                    html+='	<img src="<?php echo base_url() ?>front-end/images/news.png" class="news-img">';
                                                    html+='	<div class="news-content">';
                                                    html+='		<a href="<?php echo base_url() ?>van-chuong/'+data[i].id+'" class="news-name">'+data[i].name+'</a>';
                                                    html+='		<span class="news-desc">'+desc+'</span>';
                                                    html+='		<a href="<?php echo base_url() ?>van-chuong/'+data[i].id+'" class="readmore">Đọc tiếp</a>';
                                                    html+='	</div>';
                                                    html+='</div>';
                                                    container.append(html); 
                                                }    
                                            }
                                        }
                                    });
                                }  
                            }
                            
                        }
                    }
                });                
                
            });
        </script>
    </head>
    <body>       

        <div id="Container">
            <?php $this->load->view('header'); ?>
            <div id="MainContent">
                <div id="VanChuongContent" style=" margin: 0 auto;width: 1024px; height: 425px; padding-top: 45px; color: #fde27e">
                    <?php foreach ($arr_news as $news) { ?>                
                        <div class="news-item">                    
                            <img class="news-img" src="<?php if ($news->image != '') {
                        echo base_url() . $news->image;
                    } else {
                        echo base_url() . 'front-end/images/news.png';
                    } ?>"/>
                            <div class="news-content">
                                <a class="news-name" href="<?php echo base_url(); ?>van-chuong/<?php echo $news->id; ?>"><?php echo $news->name; ?></a>
                                <span class="news-desc"><?php
                                if (strlen($news->description) < 200) {
                                    echo $news->description;
                                } else {
                                    echo substr($news->description, 0, 200) . '...';
                                }
                        ?></span>                        
                                <a class="readmore" href="<?php echo base_url(); ?>van-chuong/<?php echo $news->id; ?>">Đọc tiếp</a>
                            </div>                                        
                        </div>                        
            <?php } ?>
                </div>
            </div>
<?php $this->load->view('menu'); ?>
<?php $this->load->view('footer'); ?>

        </div>
    </body>
</html>
